//
//  WKMainViewController.swift
//  WKWeibo
//
//  Created by 恋guang年 on 16/3/25.
//  Copyright © 2016年 恋guang年. All rights reserved.
//

import UIKit

class WKMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
       //设置tabbar为自定义的 其为只读属性 用KVC赋值
        setValue(WKMainTabBar(), forKey: "tabBar")
        //首页
        let homeVC = WKHomeTableViewController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
       
        //消息
        let messageVC = WKMessageTableViewController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        
        //发现
        let discoverVC = WKDiscoverTableViewController()
        addChildViewController(discoverVC, title: "发现", imageName: "tabbar_discover")
        
        //我
        let profileVC = WKProfileTableViewController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")
      
    }

    ///  添加子控制器 childController:要添加自控器 title:标题 imageName: tabBarItem.image
    func addChildViewController(childController: UIViewController, title:String , imageName:String) {
        
        childController.title = title;
        childController.tabBarItem.image = UIImage(named: imageName)
        let heightImageName = imageName + "_highlighted"
       
        // 设置高亮图片.默认情况下选中图片会被渲染成蓝色的.想要使用图片原来的颜色
        childController.tabBarItem.selectedImage = UIImage(named: heightImageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置tabBarItem 选中状态字体颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        //添加到tabbarcontroller控制器中
        addChildViewController(UINavigationController(rootViewController: childController))
        
    }
 


}
